public class Adobe_LeadActivities {

    public Adobe_LeadActivities(ApexPages.StandardController controller) {

    }


                List<wrapperTaksANDEvenets> Activities;
                
                public List<wrapperTaksANDEvenets> getAllActivities()
                {
                  Activities=new List<wrapperTaksANDEvenets>();
                        List<Lead> lstLeads=[select Id,Contact__c from Lead where Contact__c=:Apexpages.currentPage().getParameters().get('id')];
                       // List<Lead> lstLeads=[select Id,Contact__c from Lead where Contact__c='003A000000XQkEI'];
                        List<Task> lstTasks=[Select Id,whatId,what.Name,whoId,who.Name,ActivityDate,OwnerId,owner.Name,Status,Subject,Priority
                                                                 from Task where whoId in :lstLeads AND isClosed=false order by ActivityDate];
                        List<Event> lstEvents=[select Id,Subject,WhoId,Who.Name,WhatId,What.Name,StartDateTime,OwnerId,Owner.Name 
                                                                        from Event where whoId in :lstLeads And StartDateTime>=:System.now() order by StartDateTime];
                        
                      /* 
                       
                        for(Task t:lstTasks)
                        {
                                wrapperTaksANDEvenets wraptask=new wrapperTaksANDEvenets(t);
                                Activities.add(wraptask);
                        }
                        for(Event e:lstEvents)
                        {
                                wrapperTaksANDEvenets wrapevent=new wrapperTaksANDEvenets(e);
                                Activities.add(wrapevent);
                        }
                    */    
                        //for(Task t:lstTasks)
                       for(Integer i=0;i<lstTasks.size();i++)
                        {
                            for(Integer j=0;j<lstEvents.size();j++)
                            {
                                    if(lstTasks[i].ActivityDate>lstEvents[j].StartDateTime)
                                    {
                                         wrapperTaksANDEvenets wrapevent=new wrapperTaksANDEvenets(lstEvents[j]);
                                         Activities.add(wrapevent);
                                         lstEvents.remove(j);
                                         j--;
                                    }
                            }
                            wrapperTaksANDEvenets wraptask=new wrapperTaksANDEvenets(lstTasks[i]);
                            Activities.add(wraptask);
                        }
                        
                return Activities;
                }
                
                



                public class wrapperTaksANDEvenets
                {
                        public String sActivityID {get;set;}
                        public String sSubject {get;set;}
                        public String sWhoId {get;set;}
                        public String sWhoName {get;set;}
                        public String sWhatId {get;set;}
                        public String sWhatName {get;set;}
                        public String sOwnerId {get;set;}
                        public String sOwnerName {get;set;}
                        public String dtActivityDataTime {get;set;}
                        public String dActivityDate {get;set;}
                        public Boolean bIsTask {get;set;}
                        public String sStatus {get;set;}
                        public String sPriority {get;set;}
                        
                        public wrapperTaksANDEvenets(Task t)
                        {
                                this.sActivityID=t.Id;
                                this.sSubject=t.Subject;
                                this.sWhoId=t.whoId;
                                this.sWhoName=t.who.Name;
                                this.swhatID=t.whatId;
                                this.sWhatName=t.what.Name;
                                this.sOwnerId=t.OwnerId;
                                this.sOwnerName=t.Owner.Name;
                                if(t.ActivityDate!=null){
                                    this.dActivityDate=t.ActivityDate.format();
                                }
                                this.bIstask=true;
                                this.sStatus=t.Status;
                                this.sPriority=t.Priority;
        
                                
                        }
                        public wrapperTaksANDEvenets(Event e)
                        {
                                this.sActivityID=e.Id;
                                this.sSubject=e.Subject;
                                this.sWhoId=e.whoId;
                                this.sWhoName=e.who.Name;
                                this.swhatID=e.whatId;
                                this.sWhatName=e.what.Name;
                                this.sOwnerId=e.OwnerId;
                                this.sOwnerName=e.Owner.Name;
                                this.dtActivityDataTime=e.StartDateTime.format('M/dd/yyyy h:mm a');
                                this.bIstask=false;
        
                        }
                        
                        
                }

}